﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using UniMana.Data;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class Training_TrainingProgram_KnownlegeInfo
    {

            public bds m_bds = new bds();


            private DBMain m_data = new DBMain();

            #region [Properties - Thuộc tính]
            public Training_TrainingPrograme_Knowlege Properties
            {
                get { return m_bds.Current as Training_TrainingPrograme_Knowlege; }
            }
            #endregion

            public Training_TrainingProgram_KnownlegeInfo(int key = -1, int groupKey=-1 /*, int typeKey =-1*/)
            {
                var IQuery = m_data.m_DCSave.Training_TrainingPrograme_Knowleges.Where(p=>p.Traning_TrainingProgrameKey == key
                                                                                       && p.Training_SubjectGroupKey ==groupKey
                                                                                       /*&& p.Catalogue_SubjectTypeKey == typeKey*/);
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Training_TrainingPrograme_Knowlege();
                    Row.Traning_TrainingProgrameKey = key;
                    Row.Training_SubjectGroupKey = groupKey;
                    /*Row.Catalogue_SubjectTypeKey = typeKey;*/
                    m_bds.Add(Row);              
                }
            }

            public void Save()
            {
                m_bds.EndEdit();
                m_data.m_DCSave.SubmitChanges();
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
    }
}
